From f8b441e344584bac989e77b0ffc064fd74b4a3be Mon Sep 17 00:00:00 2001
From: Vladislav Tarakanov <vladislav.tarakanov@bk.ru>
Date: Wed, 20 Mar 2024 21:48:34 +0400
Subject: [PATCH 2/6] Local patches

Change-Id: I09a10411189787fe0f5226e97a11fb21f9997d7a
---
 include/vcl/oldprintadaptor.hxx           |   1 +
 include/vcl/print.hxx                     |  16 ++
 offapi/UnoApi_offapi.mk                   |   1 +
 offapi/com/sun/star/view/XCalcScaling.idl |  51 ++++
 sc/inc/docuno.hxx                         |   5 +-
 sc/source/ui/inc/pfuncache.hxx            |  12 +-
 sc/source/ui/inc/printfun.hxx             |  35 ++-
 sc/source/ui/unoobj/docuno.cxx            | 101 ++++++--
 sc/source/ui/view/pfuncache.cxx           |  13 +-
 sc/source/ui/view/printfun.cxx            |  55 +++-
 sfx2/source/view/viewprn.cxx              |  15 ++
 vcl/inc/printdlg.hxx                      |  20 ++
 vcl/source/gdi/oldprintadaptor.cxx        |   5 +
 vcl/source/gdi/print.cxx                  |   1 +
 vcl/source/gdi/print3.cxx                 |  35 ++-
 vcl/source/window/printdlg.cxx            | 296 +++++++++++++++++++++-
 vcl/uiconfig/ui/printdialog.ui            | 291 +++++++++++++++++++++
 vcl/unx/generic/print/genprnpsp.cxx       |   1 +
 18 files changed, 907 insertions(+), 47 deletions(-)
 create mode 100644 offapi/com/sun/star/view/XCalcScaling.idl

diff --git a/include/vcl/oldprintadaptor.hxx b/include/vcl/oldprintadaptor.hxx
index 3b74b0d76783..4f24855e8cef 100644
--- a/include/vcl/oldprintadaptor.hxx
+++ b/include/vcl/oldprintadaptor.hxx
@@ -43,6 +43,7 @@ namespace vcl
         void EndPage();
 
         virtual int  getPageCount() const override;
+        virtual css::uno::Any getScale(int key) const override;
         virtual css::uno::Sequence< css::beans::PropertyValue > getPageParameters( int i_nPage ) const override;
         virtual void printPage( int i_nPage ) const override;
     };
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index f7da5569b2ed..31bae13e42b7 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -82,6 +82,9 @@ private:
     Size                        maPaperSize;
     Size                        maPrintPageSize;
     ErrCode                     mnError;
+    sal_uInt16                  maScaleAll;
+    sal_uInt16                  maScaleToPage;
+    Size                        maScaleToItem;
     sal_uInt16                  mnPageQueueSize;
     sal_uInt16                  mnCopyCount;
     bool                        mbDefPrinter;
@@ -93,6 +96,7 @@ private:
     bool                        mbNewJobSetup;
     bool                        mbSinglePrintJobs;
     bool                        mbUsePrintSetting;
+    bool                        mbResetPrintArea;
 
     VCL_DLLPRIVATE void         ImplInitData();
     VCL_DLLPRIVATE void         ImplInit( SalPrinterQueueInfo* pInfo );
@@ -222,10 +226,18 @@ public:
     VCL_DLLPRIVATE void         SetPrinterOptions( const vcl::printer::Options& rOptions );
     const vcl::printer::Options& GetPrinterOptions() const { return( *mpPrinterOptions ); }
 
+    void                        ResetPrintArea(bool bReset) { mbResetPrintArea = bReset; }
+    bool                        IsPrintAreaReset() { return mbResetPrintArea; }
     void                        SetUsePrintDialogSetting(bool bUsed) { mbUsePrintSetting = bUsed; }
     bool                        IsUsePrintDialogSetting() { return mbUsePrintSetting; }
     void                        SetPrintPageSize(Size aPrintPageSize) { maPrintPageSize = aPrintPageSize; }
     Size                        GetPrintPageSize() { return maPrintPageSize; }
+    void                        SetScaleAll( sal_uInt16 aScaleAll) { maScaleAll = aScaleAll; }
+    sal_uInt16                  GetScaleAll() { return maScaleAll; }
+    void                        SetScaleToPage( sal_uInt16 aScaleToPage) { maScaleToPage = aScaleToPage; }
+    sal_uInt16                  GetScaleToPage() { return maScaleToPage; }
+    void                        SetScaleToItem( Size aScaleToItem) { maScaleToItem = aScaleToItem; }
+    Size                        GetScaleToItem() { return maScaleToItem; }
     bool                        SetOrientation( Orientation eOrient );
     Orientation                 GetOrientation() const;
     void                        SetDuplexMode( DuplexMode );
@@ -423,6 +435,7 @@ public:
 
     /// App must override this
     virtual int                         getPageCount() const = 0;
+    virtual css::uno::Any               getScale(int key) const = 0;
 
     /** Get the page parameters
 
@@ -460,6 +473,7 @@ public:
     // the benefit of vcl's plugins.
     // Still: DO NOT USE OUTSIDE VCL
                       int               getFilteredPageCount() const;
+                      css::uno::Any     getFilteredScale(int key) const;
     VCL_DLLPRIVATE    PageSize          getPageFile( int i_inUnfilteredPage, GDIMetaFile& rMtf,
                                             bool i_bMayUseCache = false );
                       PageSize          getFilteredPageFile( int i_nFilteredPage, GDIMetaFile& o_rMtf,
@@ -481,10 +495,12 @@ public:
                       bool              getPrinterModified() const;
     VCL_DLLPRIVATE    void              pushPropertiesToPrinter();
     VCL_DLLPRIVATE    void              resetPaperToLastConfigured();
+    VCL_DLLPRIVATE    void              resetPrintArea();
                       void              setJobState( css::view::PrintableState );
     VCL_DLLPRIVATE    void              setupPrinter( weld::Window* i_pDlgParent );
 
     VCL_DLLPRIVATE    int               getPageCountProtected() const;
+    VCL_DLLPRIVATE    css::uno::Any     getScaleProtected(int key) const;
     VCL_DLLPRIVATE    css::uno::Sequence< css::beans::PropertyValue >
                                         getPageParametersProtected( int i_nPage ) const;
 
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 7ee71bb984c1..61c724990ff0 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -4234,6 +4234,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/view,\
 	PrintableState \
 	PrintableStateEvent \
 	SelectionType \
+	XCalcScaling \
 	XControlAccess \
 	XFormLayerAccess \
 	XLineCursor \
diff --git a/offapi/com/sun/star/view/XCalcScaling.idl b/offapi/com/sun/star/view/XCalcScaling.idl
new file mode 100644
index 000000000000..f1d2fb041e13
--- /dev/null
+++ b/offapi/com/sun/star/view/XCalcScaling.idl
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+module com {  module sun {  module star {  module view {
+
+
+/** represents something that can be rendered.
+
+    @since OOo 1.1.2
+ */
+published interface XCalcScaling : com::sun::star::uno::XInterface
+{
+
+    /** @returns
+            the count of renderers (based on paper count of a document, for example).
+
+        <p> If a selection is given, the count has to be calculated
+            based on this selection. The other methods of this interface
+            will rely on this value if called.
+
+        <p> If the selection contains a valid XModel interface,
+            it is assumed that the whole document should be rendered.
+            If the selection is empty, nothing should be rendered.
+
+        @see RenderOptions
+     */
+    any getCalcScaling( [in] long key );
+
+};
+
+
+}; }; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 23de1dad63ce..a1f55772f398 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -26,6 +26,7 @@
 #include <svl/lstner.hxx>
 #include <svx/fmdmod.hxx>
 #include <com/sun/star/view/XRenderable.hpp>
+#include <com/sun/star/view/XCalcScaling.hpp>
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 #include <com/sun/star/document/XActionLockable.hpp>
 #include <com/sun/star/document/XLinkTargetSupplier.hpp>
@@ -90,7 +91,8 @@ class SC_DLLPUBLIC ScModelObj : public SfxBaseModel,
                     public css::lang::XServiceInfo,
                     public css::util::XChangesNotifier,
                     public css::chart2::XDataProviderAccess,
-                    public css::sheet::opencl::XOpenCLSelection
+                    public css::sheet::opencl::XOpenCLSelection,
+                    public css::view::XCalcScaling
 {
 private:
     SfxItemPropertySet      aPropSet;
@@ -182,6 +184,7 @@ public:
                                     const css::uno::Sequence< css::beans::PropertyValue >& xOptions ) override;
     virtual void SAL_CALL   render( sal_Int32 nRenderer, const css::uno::Any& aSelection,
                                     const css::uno::Sequence< css::beans::PropertyValue >& xOptions ) override;
+    virtual css::uno::Any SAL_CALL getCalcScaling(int key) override;
 
                             /// XLinkTargetSupplier
     virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL
diff --git a/sc/source/ui/inc/pfuncache.hxx b/sc/source/ui/inc/pfuncache.hxx
index 7cd286f39223..78ab29d23e9b 100644
--- a/sc/source/ui/inc/pfuncache.hxx
+++ b/sc/source/ui/inc/pfuncache.hxx
@@ -24,6 +24,8 @@
 #include <rangelst.hxx>
 #include <printopt.hxx>
 
+#include <com/sun/star/awt/Size.hpp>
+
 class ScDocShell;
 class ScMarkData;
 class OutputDevice;
@@ -93,10 +95,17 @@ class ScPrintFuncCache
     Size                    aPrintPageSize;          // print page size in Print dialog
     bool                    bPrintPageLandscape;     // print page orientation in Print dialog
     bool                    bUsePrintDialogSetting;  // use Print dialog setting
+    sal_uInt16              maScaleAll;               // print page scale all in Print dialog
+    sal_uInt16              maScaleToPage;            // print scale to page in Print dialog
+    Size                    maScaleToItem;            // print scale to item in Print dialog
+    sal_uInt16              maGenScaling;
+    sal_uInt16              maPageScaling;
+    css::awt::Size                    maWHScaling;
 
 public:
             ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark, ScPrintSelectionStatus aStatus,
-                             Size aPageSize = {}, bool bLandscape = false, bool bUse = false);
+                             Size aPageSize = {}, bool bLandscape = false, bool bUse = false,
+                             sal_uInt16 aScaleAll = 0, sal_uInt16 aScaleToPage = 0, Size aScaleToItem = {});
             ~ScPrintFuncCache();
 
     bool    IsSameSelection( const ScPrintSelectionStatus& rStatus ) const;
@@ -105,6 +114,7 @@ public:
     bool    FindLocation( const ScAddress& rCell, ScPrintPageLocation& rLocation ) const;
 
     tools::Long    GetPageCount() const                { return nTotalPages; }
+    css::uno::Any  GetScale(int key) const             { return (key == 0? css::uno::Any(maGenScaling) : key == 1? css::uno::Any(maWHScaling) : css::uno::Any(maPageScaling)); }
     tools::Long    GetFirstAttr( SCTAB nTab ) const    { return nFirstAttr[nTab]; }
     SCTAB   GetTabForPage( tools::Long nPage ) const;
     tools::Long    GetTabStart( SCTAB nTab ) const;
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index 2e9dd7bb49d1..c666c6a85c1c 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -24,6 +24,8 @@
 #include <pagepar.hxx>
 #include <editutil.hxx>
 
+#include <com/sun/star/awt/Size.hpp>
+
 class SfxPrinter;
 class ScDocShell;
 class ScDocument;
@@ -315,6 +317,13 @@ private:
     Size                aPrintPageSize;         // print page size in Print dialog
     bool                bPrintPageLandscape;    // print page orientation in Print dialog
     bool                bUsePrintDialogSetting; // use Print dialog setting
+    sal_uInt16          maScaleAll;             // print page scale all in Print dialog
+    sal_uInt16          maScaleToPage;          // print scale to page in Print dialog
+    Size                maScaleToItem;          // print scale to item in Print dialog
+
+    sal_uInt16          maGenScaling;             // print page scale all in Print dialog
+    sal_uInt16          maPageScaling;          // print scale to page in Print dialog
+    css::awt::Size                maWHScaling;          // print scale to item in Print dialog
 
 public:
                     ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
@@ -324,13 +333,19 @@ public:
                                  ScPageBreakData* pData = nullptr,
                                  Size aPrintPageSize = {},
                                  bool bPrintPageLandscape = false,
-                                 bool bUsePrintDialogSetting = false );
+                                 bool bUsePrintDialogSetting = false,
+                                 sal_uInt16 maScaleAll = 0,
+                                 sal_uInt16 maScaleToPage = 0,
+                                 Size maScaleToItem = {} );
 
                     ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter,
-                                const ScPrintState& rState, const ScPrintOptions* pOptions,
-                                Size aPrintPageSize = {},
-                                bool bPrintPageLandscape = false,
-                                bool bUsePrintDialogSetting = false );
+                                 const ScPrintState& rState, const ScPrintOptions* pOptions,
+                                 Size aPrintPageSize = {},
+                                 bool bPrintPageLandscape = false,
+                                 bool bUsePrintDialogSetting = false,
+                                 sal_uInt16 maScaleAll = 0,
+                                 sal_uInt16 maScaleToPage = 0,
+                                 Size maScaleToItem = {} );
 
                     // ctors for device other than printer - for preview and pdf:
 
@@ -343,7 +358,10 @@ public:
                                  const ScPrintState& rState,
                                  const ScPrintOptions* pOptions, Size aPrintPageSize = {},
                                  bool bPrintPageLandscape = false,
-                                 bool bUsePrintDialogSetting = false);
+                                 bool bUsePrintDialogSetting = false,
+                                 sal_uInt16 maScaleAll = 0,
+                                 sal_uInt16 maScaleToPage = 0,
+                                 Size maScaleToItem = {} );
 
                     ~ScPrintFunc();
 
@@ -392,6 +410,11 @@ public:
 
     bool HasPrintRange() const { return mbHasPrintRange;}
 
+    // param for printdlg
+    sal_uInt16      GetGenScaling() const  { return maGenScaling; }
+    sal_uInt16      GetPageScaling() const  { return maPageScaling; }
+    css::awt::Size  GetWHScaling() const  { return maWHScaling; }
+
 private:
     void            Construct( const ScPrintOptions* pOptions );
     void            InitParam( const ScPrintOptions* pOptions );
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index d70716b0a4c1..145f9f5506d5 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1310,6 +1310,7 @@ uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
     SC_QUERYINTERFACE( util::XChangesNotifier )
     SC_QUERYINTERFACE( sheet::opencl::XOpenCLSelection )
     SC_QUERYINTERFACE( chart2::XDataProviderAccess )
+    SC_QUERYINTERFACE( view::XCalcScaling )
 
     uno::Any aRet(SfxBaseModel::queryInterface( rType ));
     if ( !aRet.hasValue()
@@ -1374,6 +1375,7 @@ uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes()
                 cppu::UnoType<lang::XServiceInfo>::get(),
                 cppu::UnoType<util::XChangesNotifier>::get(),
                 cppu::UnoType<sheet::opencl::XOpenCLSelection>::get(),
+                cppu::UnoType<view::XCalcScaling>::get(),
             } );
     }();
     return aTypes;
@@ -1570,21 +1572,29 @@ static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, too
     return bRangeValid;
 }
 
- static void lcl_SetPrintPage(const uno::Sequence<beans::PropertyValue>& rOptions, Size& aSize,
-                             bool& bLandscape, bool& bUsed)
+static Printer* lcl_GetPrinter(const uno::Sequence<beans::PropertyValue>& rOptions)
 {
+    Printer* pPrinter = nullptr;
     OutputDevice* pDev = lcl_GetRenderDevice(rOptions);
     if (pDev && pDev->GetOutDevType() == OUTDEV_PRINTER)
+        pPrinter = dynamic_cast<Printer*>(pDev);
+    return pPrinter;
+}
+static Size lcl_GetPrintPageSize(Size aSize)
+{
+    aSize.setWidth(o3tl::convert(aSize.Width(), o3tl::Length::mm100, o3tl::Length::twip));
+    aSize.setHeight(o3tl::convert(aSize.Height(), o3tl::Length::mm100, o3tl::Length::twip));
+    return aSize;
+}
+
+static void lcl_SetScaling(const uno::Sequence<beans::PropertyValue>& rOptions, sal_uInt16& aScaleAll, sal_uInt16& aScaleToPage, Size& aScaleToItem)
+{
+    Printer* pPrinter = lcl_GetPrinter(rOptions);
+    if (pPrinter && pPrinter->IsUsePrintDialogSetting())
     {
-        Printer* pPrinter = dynamic_cast<Printer*>(pDev);
-        if (pPrinter && pPrinter->IsUsePrintDialogSetting())
-        {
-            bUsed = true;
-            bLandscape = (pPrinter->GetOrientation() == Orientation::Landscape);
-            aSize = pPrinter->GetPrintPageSize();
-            aSize.setWidth(o3tl::convert(aSize.Width(), o3tl::Length::mm100, o3tl::Length::twip));
-            aSize.setHeight(o3tl::convert(aSize.Height(), o3tl::Length::mm100, o3tl::Length::twip));
-        }
+        aScaleAll = pPrinter->GetScaleAll();
+        aScaleToPage = pPrinter->GetScaleToPage();
+        aScaleToItem = pPrinter->GetScaleToItem();
     }
 }
 
@@ -1760,6 +1770,7 @@ bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
 sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
     const uno::Sequence<beans::PropertyValue>& rOptions)
 {
+    //
     SolarMutexGuard aGuard;
     if (!pDocShell)
     {
@@ -1775,18 +1786,36 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
         return 0;
 
     Size aPrintPageSize;
+    bool bPrintAreaReset = false;
     bool bPrintPageLandscape = false;
     bool bUsePrintDialogSetting = false;
-    lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting);
+    sal_uInt16 aScaleAll;
+    sal_uInt16 aScaleToPage;
+    Size aScaleToItem;
+    Printer* pPrinter = lcl_GetPrinter(rOptions);
+    if (pPrinter)
+    {
+        if (pPrinter->IsUsePrintDialogSetting())
+        {
+            bUsePrintDialogSetting = true;
+            bPrintPageLandscape = (pPrinter->GetOrientation() == Orientation::Landscape);
+            aPrintPageSize = lcl_GetPrintPageSize(pPrinter->GetPrintPageSize());
+            lcl_SetScaling(rOptions, aScaleAll, aScaleToPage, aScaleToItem);
+        }
+        else // reset the print area created by the Print Dialog to the page style's print area.
+            bPrintAreaReset = pPrinter->IsPrintAreaReset();
+    }
 
     //  The same ScPrintFuncCache object in pPrintFuncCache is used as long as
     //  the same selection is used (aStatus) and the document isn't changed
     //  (pPrintFuncCache is cleared in Notify handler)
 
-    if (!pPrintFuncCache || !pPrintFuncCache->IsSameSelection(aStatus) || bUsePrintDialogSetting)
+    if (!pPrintFuncCache || !pPrintFuncCache->IsSameSelection(aStatus) || bUsePrintDialogSetting
+        || bPrintAreaReset)
     {
         pPrintFuncCache.reset(new ScPrintFuncCache(pDocShell, aMark, aStatus, aPrintPageSize,
-                                                   bPrintPageLandscape, bUsePrintDialogSetting));
+                                                   bPrintPageLandscape, bUsePrintDialogSetting,
+                                                   aScaleAll, aScaleToPage, aScaleToItem));
     }
     sal_Int32 nPages = pPrintFuncCache->GetPageCount();
 
@@ -1839,6 +1868,11 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
     return (nSelectCount > 0) ? nSelectCount : 1;
 }
 
+css::uno::Any ScModelObj::getCalcScaling(int key)
+{
+    return pPrintFuncCache->GetScale(key);
+}
+
 static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, std::u16string_view rPagesStr, sal_Int32 nTotalPages )
 {
     if ( rPagesStr.empty() )
@@ -2015,20 +2049,35 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
         Size aPrintPageSize;
         bool bPrintPageLandscape = false;
         bool bUsePrintDialogSetting = false;
-        lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting);
+        sal_uInt16 aScaleAll;
+        sal_uInt16 aScaleToPage;
+        Size aScaleToItem;
+        Printer* pPrinter = lcl_GetPrinter(rOptions);
+        if (pPrinter)
+        {
+            if (pPrinter->IsUsePrintDialogSetting())
+            {
+                bUsePrintDialogSetting = true;
+                bPrintPageLandscape = (pPrinter->GetOrientation() == Orientation::Landscape);
+                aPrintPageSize = lcl_GetPrintPageSize(pPrinter->GetPrintPageSize());
+                lcl_SetScaling(rOptions, aScaleAll, aScaleToPage, aScaleToItem);
+            }
+        }
 
         std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc;
         if (m_pPrintState && m_pPrintState->nPrintTab == nTab)
             pPrintFunc.reset(new ScPrintFunc(pDocShell, pDocShell->GetPrinter(), *m_pPrintState,
                                              &aStatus.GetOptions(), aPrintPageSize,
                                              bPrintPageLandscape,
-                                             bUsePrintDialogSetting));
+                                             bUsePrintDialogSetting, aScaleAll,
+                                             aScaleToPage, aScaleToItem));
         else
             pPrintFunc.reset(new ScPrintFunc(pDocShell, pDocShell->GetPrinter(), nTab,
                                              pPrintFuncCache->GetFirstAttr(nTab), nTotalPages,
                                              pSelRange, &aStatus.GetOptions(), nullptr,
                                              aPrintPageSize, bPrintPageLandscape,
-                                             bUsePrintDialogSetting));
+                                             bUsePrintDialogSetting, aScaleAll,
+                                             aScaleToPage, aScaleToItem));
         pPrintFunc->SetRenderFlag( true );
 
         sal_Int32 nContent = 0;
@@ -2251,7 +2300,20 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
     Size aPrintPageSize;
     bool bPrintPageLandscape = false;
     bool bUsePrintDialogSetting = false;
-    lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting);
+    sal_uInt16 aScaleAll;
+    sal_uInt16 aScaleToPage;
+    Size aScaleToItem;
+    Printer* pPrinter = lcl_GetPrinter(rOptions);
+    if (pPrinter)
+    {
+        if (pPrinter->IsUsePrintDialogSetting())
+        {
+            bUsePrintDialogSetting = true;
+            bPrintPageLandscape = (pPrinter->GetOrientation() == Orientation::Landscape);
+            aPrintPageSize = lcl_GetPrintPageSize(pPrinter->GetPrintPageSize());
+            lcl_SetScaling(rOptions, aScaleAll, aScaleToPage, aScaleToItem);
+        }
+    }
 
     //  to increase performance, ScPrintState might be used here for subsequent
     //  pages of the same sheet
@@ -2261,7 +2323,8 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
         && ! pSelRange) // tdf#120161 use selection to set required printed area
         pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, *m_pPrintState, &aStatus.GetOptions(),
                                          aPrintPageSize, bPrintPageLandscape,
-                                         bUsePrintDialogSetting));
+                                         bUsePrintDialogSetting, aScaleAll,
+                                         aScaleToPage, aScaleToItem));
     else
         pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions()));
 
diff --git a/sc/source/ui/view/pfuncache.cxx b/sc/source/ui/view/pfuncache.cxx
index 078633da5da0..1e7fe55235e8 100644
--- a/sc/source/ui/view/pfuncache.cxx
+++ b/sc/source/ui/view/pfuncache.cxx
@@ -29,7 +29,7 @@
 
 ScPrintFuncCache::ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark,
                                    ScPrintSelectionStatus aStatus, Size aPageSize, bool bLandscape,
-                                   bool bUsed)
+                                   bool bUsed, sal_uInt16 aScaleAll, sal_uInt16 aScaleToPage, Size aScaleToItem)
     :
     aSelection(std::move( aStatus )),
     pDocSh( pD ),
@@ -37,7 +37,10 @@ ScPrintFuncCache::ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark,
     bLocInitialized( false ),
     aPrintPageSize( aPageSize ),
     bPrintPageLandscape( bLandscape ),
-    bUsePrintDialogSetting( bUsed )
+    bUsePrintDialogSetting( bUsed ),
+    maScaleAll (aScaleAll),
+    maScaleToPage (aScaleToPage),
+    maScaleToItem (aScaleToItem)
 {
     //  page count uses the stored cell widths for the printer anyway,
     //  so ScPrintFunc with the document's printer can be used to count
@@ -69,7 +72,11 @@ ScPrintFuncCache::ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark,
         {
             ScPrintFunc aFunc(pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange,
                               &aSelection.GetOptions(), nullptr, aPrintPageSize,
-                              bPrintPageLandscape, bUsePrintDialogSetting);
+                              bPrintPageLandscape, bUsePrintDialogSetting, maScaleAll,
+                              maScaleToPage, maScaleToItem);
+            maGenScaling = aFunc.GetGenScaling();
+            maWHScaling = aFunc.GetWHScaling();
+            maPageScaling = aFunc.GetPageScaling();
             nThisTab = aFunc.GetTotalPages();
             nFirstAttr.push_back( aFunc.GetFirstPageNo() );         // from page style or previous sheet
         }
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index c526781d1346..ae8ddcbbb9a1 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -197,7 +197,8 @@ void ScPrintFunc::Construct( const ScPrintOptions* pOptions )
 
 ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab, tools::Long nPage,
                          tools::Long nDocP, const ScRange* pArea, const ScPrintOptions* pOptions,
-                         ScPageBreakData* pData, Size aSize, bool bPrintLandscape, bool bUsed)
+                         ScPageBreakData* pData, Size aSize, bool bPrintLandscape, bool bUsed,
+                         sal_uInt16 aScaleAll, sal_uInt16 aScaleToPage, Size aScaleToItem)
     :   pDocShell           ( pShell ),
         rDoc(pDocShell->GetDocument()),
         pPrinter            ( pNewPrinter ),
@@ -217,7 +218,10 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab
         pPageData           ( pData ),
         aPrintPageSize      ( aSize ),
         bPrintPageLandscape ( bPrintLandscape ),
-        bUsePrintDialogSetting ( bUsed )
+        bUsePrintDialogSetting ( bUsed ),
+        maScaleAll (aScaleAll),
+        maScaleToPage (aScaleToPage),
+        maScaleToItem (aScaleToItem)
 {
     pDev = pPrinter.get();
     aSrcOffset = pPrinter->PixelToLogic(pPrinter->GetPageOffsetPixel(), MapMode(MapUnit::Map100thMM));
@@ -229,7 +233,7 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab
 
 ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, const ScPrintState& rState,
                          const ScPrintOptions* pOptions, Size aSize, bool bPrintLandscape,
-                         bool bUsed)
+                         bool bUsed, sal_uInt16 aScaleAll, sal_uInt16 aScaleToPage, Size aScaleToItem)
     :   pDocShell           ( pShell ),
         rDoc(pDocShell->GetDocument()),
         pPrinter            ( pNewPrinter ),
@@ -242,7 +246,10 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, const ScPr
         pPageData           ( nullptr ),
         aPrintPageSize      ( aSize ),
         bPrintPageLandscape ( bPrintLandscape ),
-        bUsePrintDialogSetting ( bUsed )
+        bUsePrintDialogSetting ( bUsed ),
+        maScaleAll (aScaleAll),
+        maScaleToPage (aScaleToPage),
+        maScaleToItem (aScaleToItem)
 {
     pDev = pPrinter.get();
 
@@ -313,7 +320,7 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
 
 ScPrintFunc::ScPrintFunc(OutputDevice* pOutDev, ScDocShell* pShell, const ScPrintState& rState,
                          const ScPrintOptions* pOptions, Size aSize, bool bPrintLandscape,
-                         bool bUsed)
+                         bool bUsed, sal_uInt16 aScaleAll, sal_uInt16 aScaleToPage, Size aScaleToItem)
     :   pDocShell           ( pShell ),
         rDoc(pDocShell->GetDocument()),
         pPrinter            ( nullptr ),
@@ -326,7 +333,10 @@ ScPrintFunc::ScPrintFunc(OutputDevice* pOutDev, ScDocShell* pShell, const ScPrin
         pPageData           ( nullptr ),
         aPrintPageSize      ( aSize ),
         bPrintPageLandscape ( bPrintLandscape ),
-        bUsePrintDialogSetting ( bUsed )
+        bUsePrintDialogSetting ( bUsed ),
+        maScaleAll (aScaleAll),
+        maScaleToPage (aScaleToPage),
+        maScaleToItem (aScaleToItem)
 {
     pDev = pOutDev;
 
@@ -983,13 +993,39 @@ void ScPrintFunc::InitParam( const ScPrintOptions* pOptions )
         sal_uInt16  nScaleAll     = pScaleItem->GetValue();
         sal_uInt16  nScaleToPages = pScaleToPagesItem->GetValue();
 
+        if(!bUsePrintDialogSetting)
+        {
+            maGenScaling = nScaleAll;
+            maWHScaling = css::awt::Size(pScaleToItem->GetWidth(), pScaleToItem->GetHeight());
+            maPageScaling = nScaleToPages;
+        }
+
+
+        if (maScaleAll && bUsePrintDialogSetting)
+        {
+            nScaleAll = maScaleAll;
+        }
+
+        if (maScaleToPage && bUsePrintDialogSetting)
+        {
+            nScaleToPages = maScaleToPage;
+            nScaleAll = 0;
+        }
+
+        bool bScaleToItem = (maScaleToItem.getWidth() > 0 || maScaleToItem.getHeight() > 0);
+
+        if (bScaleToItem)
+        {
+            nScaleAll = 0;
+        }
+
         aTableParam.bScaleNone      = (nScaleAll     == 100);
         aTableParam.bScaleAll       = (nScaleAll      > 0  );
-        aTableParam.bScaleTo        = pScaleToItem->IsValid();
+        aTableParam.bScaleTo        = bUsePrintDialogSetting ? bScaleToItem : pScaleToItem->IsValid();
         aTableParam.bScalePageNum   = (nScaleToPages  > 0  );
         aTableParam.nScaleAll       = nScaleAll;
-        aTableParam.nScaleWidth     = pScaleToItem->GetWidth();
-        aTableParam.nScaleHeight    = pScaleToItem->GetHeight();
+        aTableParam.nScaleWidth     = bUsePrintDialogSetting && maScaleToItem.getWidth() > 0 ? maScaleToItem.getWidth() : pScaleToItem->GetWidth();
+        aTableParam.nScaleHeight    = bUsePrintDialogSetting && maScaleToItem.getHeight() > 0 ? maScaleToItem.getHeight() : pScaleToItem->GetHeight();
         aTableParam.nScalePageNum   = nScaleToPages;
     }
     else
@@ -2656,6 +2692,7 @@ void ScPrintFunc::ApplyPrintSettings()
     pPrinter->SetPaper( ePaper );
     if ( PAPER_USER == ePaper )
     {
+        //
         MapMode aPrinterMode = pPrinter->GetMapMode();
         MapMode aLocalMode( MapUnit::MapTwip );
         pPrinter->SetMapMode( aLocalMode );
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 5ada786ba108..d6c3970e40e6 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/document/XDocumentProperties.hpp>
 #include <com/sun/star/view/XRenderable.hpp>
 #include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <com/sun/star/view/XCalcScaling.hpp>
 
 #include <comphelper/propertyvalue.hxx>
 #include <officecfg/Office/Common.hxx>
@@ -92,6 +93,7 @@ public:
     virtual void Notify( SfxBroadcaster&, const SfxHint& ) override;
 
     virtual int  getPageCount() const override;
+    virtual css::uno::Any  getScale(int key) const override;
     virtual Sequence< beans::PropertyValue > getPageParameters( int i_nPage ) const override;
     virtual void printPage( int i_nPage ) const override;
     virtual void jobStarted() override;
@@ -237,6 +239,19 @@ int SfxPrinterController::getPageCount() const
     return nPages;
 }
 
+css::uno::Any SfxPrinterController::getScale(int key) const
+{
+    css::uno::Any scaling;
+    if ( mxRenderable.is() )
+    {
+        Reference< view::XCalcScaling > mxCalcScaling(mxRenderable, UNO_QUERY);
+        if ( mxCalcScaling.is() )
+            scaling = mxCalcScaling->getCalcScaling(key);
+    }
+
+    return scaling;
+}
+
 Sequence< beans::PropertyValue > SfxPrinterController::getPageParameters( int i_nPage ) const
 {
     VclPtr<Printer> xPrinter( getPrinter() );
diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx
index 26d5ebb2777d..42210729cb9b 100644
--- a/vcl/inc/printdlg.hxx
+++ b/vcl/inc/printdlg.hxx
@@ -106,6 +106,8 @@ namespace vcl
         void previewBackward();
         void previewFirst();
         void previewLast();
+        void updateScalePreview();
+        void initScaleFromSheetStyle();
 
     private:
 
@@ -173,6 +175,18 @@ namespace vcl
         std::unique_ptr<weld::Expander>         mxLayoutExpander;
         std::unique_ptr<weld::Widget>           mxCustom;
 
+        // scale mode
+        std::unique_ptr<weld::ComboBox> mxLbScaleMode;
+        std::unique_ptr<weld::Widget> mxBxScaleAll;
+        std::unique_ptr<weld::MetricSpinButton> mxEdScaleAll;
+        std::unique_ptr<weld::Widget> mxGrHeightWidth;
+        std::unique_ptr<weld::SpinButton> mxEdScalePageWidth;
+        std::unique_ptr<weld::CheckButton> mxCbScalePageWidth;
+        std::unique_ptr<weld::SpinButton> mxEdScalePageHeight;
+        std::unique_ptr<weld::CheckButton> mxCbScalePageHeight;
+        std::unique_ptr<weld::Widget> mxBxScalePageNum;
+        std::unique_ptr<weld::SpinButton> mxEdScalePageNum;
+
         OUString                                maPrintToFileText;
         OUString                                maPrintText;
         OUString                                maDefPrtText;
@@ -183,6 +197,8 @@ namespace vcl
         sal_Int32                               mnCurPage;
         sal_Int32                               mnCachedPages;
 
+        Timer                                   maScaleTimer;
+
         bool                                    mbCollateAlwaysOff;
 
         std::vector<std::unique_ptr<weld::Widget>>
@@ -217,6 +233,8 @@ namespace vcl
         DECL_LINK( MetricSpinModifyHdl, weld::MetricSpinButton&, void );
         DECL_LINK( ToggleHdl, weld::Toggleable&, void );
 
+        DECL_LINK( ScaleHdl, weld::ComboBox&, void);
+
         DECL_LINK( UIOption_CheckHdl, weld::Toggleable&, void );
         DECL_LINK( UIOption_RadioHdl, weld::Toggleable&, void );
         DECL_LINK( UIOption_SelectHdl, weld::ComboBox&, void );
@@ -233,6 +251,8 @@ namespace vcl
         void updateOrientationBox( bool bAutomatic = true );
         void updatePageSize( int nOrientation );
         void updatePageRange( const sal_Int32 nPages );
+        void updatePageScale( sal_Int16 nScaleAll, sal_Int16 nScaleToPag, Size nScaleToItem );
+        Size getPageScaleSize();
         bool hasOrientationChanged() const;
         void setPreviewText();
         void updatePrinterText();
diff --git a/vcl/source/gdi/oldprintadaptor.cxx b/vcl/source/gdi/oldprintadaptor.cxx
index 599e1a543f3c..f9a1e2d0fcb8 100644
--- a/vcl/source/gdi/oldprintadaptor.cxx
+++ b/vcl/source/gdi/oldprintadaptor.cxx
@@ -89,6 +89,11 @@ int  OldStylePrintAdaptor::getPageCount() const
     return int(mpData->maPages.size());
 }
 
+css::uno::Any  OldStylePrintAdaptor::getScale(int key) const
+{
+    return css::uno::Any(0);
+}
+
 Sequence< PropertyValue > OldStylePrintAdaptor::getPageParameters( int i_nPage ) const
 {
     css::awt::Size aSize;
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 1f92fdb95eda..5a45a8c79605 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -1326,6 +1326,7 @@ bool Printer::SetPaperSizeUser( const Size& rSize )
 
     if(bNeedToChange)
     {
+        //
         JobSetup      aJobSetup = maJobSetup;
         ImplJobSetup& rData = aJobSetup.ImplGetData();
         rData.SetPaperFormat( PAPER_USER );
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 5fb7b2b286d1..07b9cdfd9f71 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -41,6 +41,8 @@
 #include <strings.hrc>
 #include <svdata.hxx>
 
+#include <iostream>
+
 #include <com/sun/star/awt/Size.hpp>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 #include <com/sun/star/ui/dialogs/FilePicker.hpp>
@@ -514,7 +516,6 @@ bool Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
             PrintDialog aDlg(xController->getWindow(), xController);
             if (!aDlg.run())
             {
-                xController->getPrinter()->SetUsePrintDialogSetting(false);
                 xController->abortJob();
                 return false;
             }
@@ -565,6 +566,13 @@ bool Printer::ExecutePrintJob(const std::shared_ptr<PrinterController>& xControl
 
 void Printer::FinishPrintJob(const std::shared_ptr<PrinterController>& xController)
 {
+    PrintDialog aDlg(xController->getWindow(), xController);
+    xController->getPrinter()->SetScaleAll(0);
+    xController->getPrinter()->SetScaleToPage(0);
+    xController->getPrinter()->SetScaleToItem({0,0});
+    aDlg.updateScalePreview();
+
+    xController->resetPrintArea();
     xController->resetPaperToLastConfigured();
     xController->jobFinished( xController->getJobState() );
 }
@@ -865,6 +873,14 @@ void PrinterController::resetPrinterOptions( bool i_bFileOutput )
     mpImplData->mxPrinter->SetPrinterOptions( aOpt );
 }
 
+// reset the print area created by the Print Dialog to the page style's print area.
+void PrinterController::resetPrintArea()
+{
+    mpImplData->mxPrinter->ResetPrintArea(true);
+    mpImplData->mxPrinter->SetUsePrintDialogSetting(false);
+    getPageCount();
+}
+
 void PrinterController::setupPrinter( weld::Window* i_pParent )
 {
     bool bRet = false;
@@ -1026,6 +1042,17 @@ int PrinterController::getPageCountProtected() const
     return nPages;
 }
 
+css::uno::Any PrinterController::getScaleProtected(int key) const
+{
+    const MapMode aMapMode( MapUnit::Map100thMM );
+
+    mpImplData->mxPrinter->Push();
+    mpImplData->mxPrinter->SetMapMode( aMapMode );
+    css::uno::Any scaling = getScale(key);
+    mpImplData->mxPrinter->Pop();
+    return scaling;
+}
+
 css::uno::Sequence< css::beans::PropertyValue > PrinterController::getPageParametersProtected( int i_nPage ) const
 {
     const MapMode aMapMode( MapUnit::Map100thMM );
@@ -1071,6 +1098,7 @@ PrinterController::PageSize PrinterController::getPageFile( int i_nUnfilteredPag
 
     // modify job setup if necessary
     PrinterController::PageSize aPageSize = mpImplData->modifyJobSetup( aPageParm );
+    //
 
     o_rMtf.SetPrefSize( aPageSize.aSize );
     o_rMtf.SetPrefMapMode( aMapMode );
@@ -1281,6 +1309,11 @@ int PrinterController::getFilteredPageCount() const
     return (getPageCountProtected() + (nDiv-1)) / nDiv;
 }
 
+css::uno::Any PrinterController::getFilteredScale(int key) const
+{
+    return getScaleProtected(key);
+}
+
 DrawModeFlags PrinterController::removeTransparencies( GDIMetaFile const & i_rIn, GDIMetaFile& o_rOut )
 {
     DrawModeFlags nRestoreDrawMode = mpImplData->mxPrinter->GetDrawMode();
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index ff3dd99dcaca..bde4740d7920 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -45,6 +45,10 @@
 #include <strings.hrc>
 #include <svdata.hxx>
 
+#include <com/sun/star/awt/Size.hpp>
+
+#include <iostream>
+
 #include <com/sun/star/beans/PropertyValue.hpp>
 
 using namespace vcl;
@@ -61,6 +65,18 @@ enum
     ORIENTATION_LANDSCAPE
 };
 
+enum
+{
+    GENERAL_SCALING,
+    WH_SCALING,
+    PAGE_SCALING
+};
+
+// List box entries "Scaling mode"
+#define SC_TPTABLE_SCALE_PERCENT    0
+#define SC_TPTABLE_SCALE_TO         1
+#define SC_TPTABLE_SCALE_TO_PAGES   2
+
 namespace {
    bool lcl_ListBoxCompare( const OUString& rStr1, const OUString& rStr2 )
    {
@@ -518,6 +534,7 @@ Size const & PrintDialog::getJobPageSize()
         if( maPController->getPageCountProtected() > 0 )
         {
             PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true );
+            //
             maFirstPageSize = aPageSize.aSize;
         }
     }
@@ -576,12 +593,25 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
     , mxRangeExpander(m_xBuilder->weld_expander("exRangeExpander"))
     , mxLayoutExpander(m_xBuilder->weld_expander("exLayoutExpander"))
     , mxCustom(m_xBuilder->weld_widget("customcontents"))
+
+    , mxLbScaleMode(m_xBuilder->weld_combo_box("comboLB_SCALEMODE"))
+    , mxBxScaleAll(m_xBuilder->weld_widget("boxSCALEALL"))
+    , mxEdScaleAll(m_xBuilder->weld_metric_spin_button("spinED_SCALEALL", FieldUnit::PERCENT))
+    , mxGrHeightWidth(m_xBuilder->weld_widget("gridWH"))
+    , mxEdScalePageWidth(m_xBuilder->weld_spin_button("spinED_SCALEPAGEWIDTH"))
+    , mxCbScalePageWidth(m_xBuilder->weld_check_button("labelWP"))
+    , mxEdScalePageHeight(m_xBuilder->weld_spin_button("spinED_SCALEPAGEHEIGHT"))
+    , mxCbScalePageHeight(m_xBuilder->weld_check_button("labelHP"))
+    , mxBxScalePageNum(m_xBuilder->weld_widget("boxNP"))
+    , mxEdScalePageNum(m_xBuilder->weld_spin_button("spinED_SCALEPAGENUM"))
+
     , maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ) )
     , maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ) )
     , maNoPageStr( VclResId( SV_PRINT_NOPAGES ) )
     , maNoPreviewStr( VclResId( SV_PRINT_NOPREVIEW ) )
     , mnCurPage( 0 )
     , mnCachedPages( 0 )
+    , maScaleTimer ("vcl wait_Impl")
     , mbCollateAlwaysOff(false)
     , mbShowLayoutFrame( true )
     , maUpdatePreviewIdle("Print Dialog Update Preview Idle")
@@ -624,6 +654,14 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
         }
     }
 
+    initScaleFromSheetStyle();
+
+    mxEdScaleAll->connect_value_changed(LINK(this, PrintDialog, MetricSpinModifyHdl));
+
+    // auto preview update through 500ms after scale change
+    maScaleTimer.SetInvokeHandler(LINK(this, PrintDialog, updatePreviewNoCacheIdle));
+    maScaleTimer.SetTimeout(500);
+
     // not printing to file
     maPController->resetPrinterOptions( false );
 
@@ -688,6 +726,8 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
     mxBrochureBtn->connect_toggled( LINK( this, PrintDialog, ToggleHdl ) );
     mxPreviewBox->connect_toggled( LINK( this, PrintDialog, ToggleHdl ) );
     mxBorderCB->connect_toggled( LINK( this, PrintDialog, ToggleHdl ) );
+    mxCbScalePageWidth->connect_toggled(LINK(this, PrintDialog, ToggleHdl));
+    mxCbScalePageHeight->connect_toggled(LINK(this, PrintDialog, ToggleHdl));
 
     // setup select hdl
     mxPrinters->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
@@ -703,8 +743,15 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
     mxCopyCountField->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl ) );
     mxNupColEdt->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl ) );
     mxNupRowsEdt->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl ) );
+    mxEdScalePageNum->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl ) );
+    mxEdScalePageHeight->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl ) );
+    mxEdScalePageWidth->connect_value_changed( LINK( this, PrintDialog, SpinModifyHdl ) );
     mxPageMarginEdt->connect_value_changed( LINK( this, PrintDialog, MetricSpinModifyHdl ) );
     mxSheetMarginEdt->connect_value_changed( LINK( this, PrintDialog, MetricSpinModifyHdl ) );
+    mxEdScaleAll->connect_value_changed( LINK( this, PrintDialog, MetricSpinModifyHdl ) );
+
+    // setup scale hdl
+    mxLbScaleMode->connect_changed(LINK(this,PrintDialog, ScaleHdl));
 
     updateNupFromPages();
 
@@ -1014,8 +1061,9 @@ void PrintDialog::updatePageRange(sal_Int32 nPages)
         {
             aBuf.append("-" + OUString::number(nPages));
         }
-        maPController->setValue("PageRange", css::uno::Any(aBuf.makeStringAndClear()));
-        setupOptionalUI();
+        OUString sRange = aBuf.makeStringAndClear();
+        mxPageRangeEdit->set_text(sRange);
+        maPController->setValue("PageRange", Any(sRange));
     }
 }
 
@@ -1041,6 +1089,42 @@ void PrintDialog::updatePageSize(int nOrientation)
     aPrt->SetUsePrintDialogSetting(true);
 }
 
+void PrintDialog::updatePageScale( sal_Int16 nScaleAll, sal_Int16 nScaleToPage, Size nScaleToItem)
+{
+    VclPtr<Printer> aPrt(maPController->getPrinter());
+
+    if (nScaleAll > 0)
+    {
+        aPrt->SetScaleAll(nScaleAll);
+        aPrt->SetScaleToPage(0);
+        aPrt->SetScaleToItem({0,0});
+    }
+    if (nScaleToPage > 0)
+    {
+        aPrt->SetScaleToPage(nScaleToPage);
+        aPrt->SetScaleAll(0);
+        aPrt->SetScaleToItem({0,0});
+    }
+    if ( nScaleToItem.getHeight() > 0 || nScaleToItem.getWidth() > 0 )
+    {
+        aPrt->SetScaleToItem(nScaleToItem);
+        aPrt->SetScaleAll(0);
+        aPrt->SetScaleToPage(0);
+    }
+
+    //updatePageSize( aPrt->GetOrientation() == Orientation::Portrait ? 1 : aPrt->GetOrientation() == Orientation::Landscape ? 2 : 0);
+}
+
+Size PrintDialog::getPageScaleSize()
+{
+    sal_Int64 width = 0, height = 0;
+    if (mxCbScalePageHeight->get_active())
+        height = mxEdScalePageHeight->get_value();
+    if (mxCbScalePageWidth->get_active())
+        width = mxEdScalePageWidth->get_value();
+    return Size(width, height);
+}
+
 void PrintDialog::updateOrientationBox( const bool bAutomatic )
 {
     if ( !bAutomatic )
@@ -1902,6 +1986,44 @@ IMPL_LINK(PrintDialog, ToggleHdl, weld::Toggleable&, rButton, void)
         }
 
     }
+    else if ( &rButton == mxCbScalePageWidth.get() )
+    {
+        if (!rButton.get_active())
+        {
+            mxEdScalePageWidth->set_text(OUString());
+            mxEdScalePageWidth->set_sensitive(false);
+            updatePageSize(mxOrientationBox->get_active());
+            updatePageScale( 100, 0, Size(0, getPageScaleSize().getHeight()) );
+        }
+        else
+        {
+            mxEdScalePageWidth->set_value(1);
+            mxEdScalePageWidth->set_sensitive(true);
+            updatePageSize(mxOrientationBox->get_active());
+            updatePageScale( 0, 0, getPageScaleSize() );
+        }
+
+        maUpdatePreviewNoCacheIdle.Start();
+    }
+    else if ( &rButton == mxCbScalePageHeight.get() )
+    {
+        if (!rButton.get_active())
+        {
+            mxEdScalePageHeight->set_text(OUString());
+            mxEdScalePageHeight->set_sensitive(false);
+            updatePageSize(mxOrientationBox->get_active());
+            updatePageScale( 100, 0, Size(getPageScaleSize().getWidth(), 0) );
+        }
+        else
+        {
+            mxEdScalePageHeight->set_value(1);
+            mxEdScalePageHeight->set_sensitive(true);
+            updatePageSize(mxOrientationBox->get_active());
+            updatePageScale( 0, 0, getPageScaleSize() );
+        }
+
+        maUpdatePreviewNoCacheIdle.Start();
+    }
 }
 
 IMPL_LINK(PrintDialog, ClickHdl, weld::Button&, rButton, void)
@@ -1963,7 +2085,54 @@ IMPL_LINK(PrintDialog, ClickHdl, weld::Button&, rButton, void)
         }
         checkControlDependencies();
     }
+}
+
+IMPL_LINK_NOARG( PrintDialog, ScaleHdl, weld::ComboBox&, void)
+{
+    mxCbScalePageHeight->set_visible(false);
+    mxCbScalePageWidth->set_visible(false);
+    mxEdScalePageHeight->set_visible(false);
+    mxEdScalePageWidth->set_visible(false);
+    mxEdScalePageNum->set_visible(false);
+    mxBxScalePageNum->set_visible(false);
+    mxEdScaleAll->set_visible(false);
+    mxBxScaleAll->set_visible(false);
 
+    mxCbScalePageHeight->set_active(false);
+    mxCbScalePageWidth->set_active(false);
+    // controls for Box "Reduce/enlarge"
+    if (mxLbScaleMode->get_active() == SC_TPTABLE_SCALE_PERCENT)
+    {
+        mxBxScaleAll->set_visible(true);
+        mxEdScaleAll->set_visible(true);
+        mxEdScaleAll->set_value(100, FieldUnit::PERCENT);
+        updatePageSize(mxOrientationBox->get_active());
+        updatePageScale(100, 0, {0, 0});
+    }
+    // controls for Grid "Scale to width/height"
+    else if (mxLbScaleMode->get_active() == SC_TPTABLE_SCALE_TO)
+    {
+        mxCbScalePageHeight->set_visible(true);
+        mxCbScalePageWidth->set_visible(true);
+        mxEdScalePageHeight->set_visible(true);
+        mxEdScalePageWidth->set_visible(true);
+        mxGrHeightWidth->set_visible(true);
+        mxEdScalePageHeight->set_value(1);
+        mxEdScalePageWidth->set_value(1);
+        updatePageSize(mxOrientationBox->get_active());
+        updatePageScale(100, 0, {0, 0});
+    }
+    // controls for Box "Scale to pages"
+    else if (mxLbScaleMode->get_active() == SC_TPTABLE_SCALE_TO_PAGES)
+    {
+        mxEdScalePageNum->set_visible(true);
+        mxBxScalePageNum->set_visible(true);
+        mxEdScalePageNum->set_value(1);
+        updatePageSize(mxOrientationBox->get_active());
+        updatePageScale(0, 1, {0, 0});
+    }
+
+    maUpdatePreviewNoCacheIdle.Start();
 }
 
 IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )
@@ -1997,7 +2166,19 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )
             maUpdatePreviewIdle.Start();
         }
 
-        updatePageSize(mxOrientationBox->get_active());
+        //updatePageSize(mxOrientationBox->get_active());
+        if (mxLbScaleMode->get_active() == SC_TPTABLE_SCALE_PERCENT)
+        {
+            updatePageScale(mxEdScaleAll->get_value(FieldUnit::PERCENT), 0, {0, 0});
+        }
+        else if (mxLbScaleMode->get_active() == SC_TPTABLE_SCALE_TO_PAGES)
+        {
+            updatePageScale(0, mxEdScalePageNum->get_value(), {0, 0});
+        }
+        else if (mxLbScaleMode->get_active() == SC_TPTABLE_SCALE_TO)
+        {
+            updatePageScale( 0, 0, getPageScaleSize() );
+        }
         setupPaperSidesBox();
     }
     else if ( &rBox == mxPaperSidesBox.get() )
@@ -2044,10 +2225,20 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )
     }
 }
 
-IMPL_LINK_NOARG(PrintDialog, MetricSpinModifyHdl, weld::MetricSpinButton&, void)
+IMPL_LINK(PrintDialog, MetricSpinModifyHdl, weld::MetricSpinButton&, rMSpin, void)
 {
-    checkControlDependencies();
-    updateNupFromPages();
+    if( &rMSpin == mxEdScaleAll.get() )
+    {
+        maScaleTimer.Stop();
+        maScaleTimer.Start();
+        updatePageSize(mxOrientationBox->get_active());
+        updatePageScale( mxEdScaleAll->get_value(FieldUnit::PERCENT), 0, {0, 0} );
+    }
+    else
+    {
+        checkControlDependencies();
+        updateNupFromPages();
+    }
 }
 
 IMPL_LINK_NOARG(PrintDialog, FocusOutHdl, weld::Widget&, void)
@@ -2091,6 +2282,18 @@ IMPL_LINK( PrintDialog, SpinModifyHdl, weld::SpinButton&, rEdit, void )
         maPController->setValue( "Collate",
                                Any( isCollate() ) );
     }
+    else if ( &rEdit == mxEdScalePageNum.get() )
+    {
+        updatePageSize(mxOrientationBox->get_active());
+        updatePageScale( 0, mxEdScalePageNum->get_value(), {0, 0} );
+        maUpdatePreviewNoCacheIdle.Start();
+    }
+    else if ( &rEdit == mxEdScalePageWidth.get() || &rEdit == mxEdScalePageHeight.get() )
+    {
+        updatePageSize(mxOrientationBox->get_active());
+        updatePageScale( 0, 0, getPageScaleSize() );
+        maUpdatePreviewNoCacheIdle.Start();
+    }
 }
 
 IMPL_LINK( PrintDialog, UIOption_CheckHdl, weld::Toggleable&, i_rBox, void )
@@ -2185,7 +2388,7 @@ IMPL_LINK( PrintDialog, UIOption_SpinModifyHdl, weld::SpinButton&, i_rBox, void
 IMPL_LINK( PrintDialog, UIOption_EntryModifyHdl, weld::Entry&, i_rBox, void )
 {
     PropertyValue* pVal = getValueForWindow( &i_rBox );
-    if( pVal )
+    if( pVal && mxPageRangesRadioButton->get_active() )
     {
         makeEnabled( &i_rBox );
 
@@ -2231,6 +2434,85 @@ void PrintDialog::previewLast()
     ActivateHdl(*mxPageEdit);
 }
 
+void PrintDialog::updateScalePreview()
+{
+    // Used in FinishPrintJob in print3.cxx to rollback scaling after closing the print dialog
+    preparePreview(false);
+}
+
+void PrintDialog::initScaleFromSheetStyle()
+{
+    // initial scaling parameters from the page style -> sheet
+    sal_uInt16 scaleAll = 0;
+    sal_uInt16 scalePage = 0;
+    css::awt::Size scaleWH = {};
+    if((maPController->getFilteredScale(GENERAL_SCALING) >>= scaleAll) && scaleAll != 0)
+    {
+        mxLbScaleMode->set_active(0);
+        // controls for Box "Reduce/enlarge"
+        mxBxScaleAll->set_visible(true);
+        // controls for Grid "Scale to width/height"
+        mxGrHeightWidth->set_visible(false);
+        // controls for Box "Scale to pages"
+        mxBxScalePageNum->set_visible(false);
+        mxEdScaleAll->set_value(scaleAll, FieldUnit::PERCENT);
+        updatePageScale(scaleAll, 0, {0, 0});
+    }
+    else if ((maPController->getFilteredScale(WH_SCALING) >>= scaleWH) && (scaleWH.Height != 0 || scaleWH.Width != 0))
+    {
+        mxLbScaleMode->set_active(1);
+        // controls for Box "Reduce/enlarge"
+        mxBxScaleAll->set_visible(false);
+        // controls for Grid "Scale to width/height"
+        mxGrHeightWidth->set_visible(true);
+        // controls for Box "Scale to pages"
+        mxBxScalePageNum->set_visible(false);
+        mxCbScalePageHeight->set_active(scaleWH.Height > 0);
+        mxCbScalePageWidth->set_active(scaleWH.Width > 0);
+
+        mxEdScalePageWidth->set_value(scaleWH.Width);
+        mxEdScalePageHeight->set_value(scaleWH.Height);
+
+        mxEdScalePageHeight->set_sensitive(scaleWH.Height > 0);
+        mxEdScalePageWidth->set_sensitive(scaleWH.Width > 0);
+        updatePageScale(0, 0, {scaleWH.Width, scaleWH.Height});
+
+    }
+    else if ((maPController->getFilteredScale(PAGE_SCALING) >>= scalePage) && scalePage != 0)
+    {
+        mxLbScaleMode->set_active(2);
+        // controls for Box "Reduce/enlarge"
+        mxBxScaleAll->set_visible(false);
+        // controls for Grid "Scale to width/height"
+        mxGrHeightWidth->set_visible(false);
+        // controls for Box "Scale to pages"
+        mxBxScalePageNum->set_visible(true);
+        mxEdScalePageNum->set_value(scalePage);
+        updatePageScale(0, scalePage, {0, 0});
+    }
+    else
+    {
+        // controls for Box "Reduce/enlarge"
+        mxBxScaleAll->set_visible(true);
+        // controls for Grid "Scale to width/height"
+        mxGrHeightWidth->set_visible(false);
+        // controls for Box "Scale to pages"
+        mxBxScalePageNum->set_visible(false);
+        mxEdScaleAll->set_value(100, FieldUnit::PERCENT);
+        // setup initial values ​​for scaling settings
+        mxEdScalePageNum->set_value(1);
+
+        mxEdScalePageWidth->set_value(1);
+        mxEdScalePageWidth->set_text(OUString());
+        mxEdScalePageWidth->set_sensitive(0);
+        mxCbScalePageWidth->set_active(0);
+
+        mxEdScalePageHeight->set_value(1);
+        mxEdScalePageHeight->set_text(OUString());
+        mxEdScalePageHeight->set_sensitive(0);
+        mxCbScalePageHeight->set_active(0);
+    }
+}
 
 static OUString getNewLabel(const OUString& aLabel, int i_nCurr, int i_nMax)
 {
diff --git a/vcl/uiconfig/ui/printdialog.ui b/vcl/uiconfig/ui/printdialog.ui
index 6f0aa80d05fd..90ae9397847f 100644
--- a/vcl/uiconfig/ui/printdialog.ui
+++ b/vcl/uiconfig/ui/printdialog.ui
@@ -38,6 +38,32 @@
     <property name="step-increment">1</property>
     <property name="page-increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="adjustmentScalingFactor">
+    <property name="lower">10</property>
+    <property name="upper">400</property>
+    <property name="value">15</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustmentPage">
+    <property name="lower">1</property>
+    <property name="upper">1000</property>
+    <property name="value">1</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustmentPage1">
+    <property name="lower">1</property>
+    <property name="upper">1000</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustmentPage2">
+    <property name="lower">1</property>
+    <property name="upper">1000</property>
+    <property name="step-increment">1</property>
+    <property name="page-increment">10</property>
+  </object>
   <object class="GtkImage" id="imgBack">
     <property name="visible">True</property>
     <property name="can-focus">False</property>
@@ -1388,6 +1414,271 @@
                                 <property name="position">2</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkFrame" id="layoutframed">
+                                <property name="visible">True</property>
+                                <property name="can-focus">False</property>
+                                <property name="label-xalign">0</property>
+                                <property name="shadow-type">none</property>
+                                <child>
+                                  <!-- n-columns=2 n-rows=2 -->
+                                  <object class="GtkGrid" id="scalegrid">
+                                    <property name="visible">True</property>
+                                    <property name="can-focus">False</property>
+                                    <property name="margin-start">12</property>
+                                    <property name="row-spacing">6</property>
+                                    <property name="column-spacing">12</property>
+                                    <child>
+                                      <object class="GtkLabel" id="labelScalingMode">
+                                        <property name="visible">True</property>
+                                        <property name="can-focus">False</property>
+                                        <property name="label" translatable="yes" context="printdialog|labelScalingMode">Scaling _mode:</property>
+                                        <property name="use-underline">True</property>
+                                        <property name="mnemonic-widget">comboLB_SCALEMODE</property>
+                                        <property name="xalign">0</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left-attach">0</property>
+                                        <property name="top-attach">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkBox" id="box4d">
+                                        <property name="visible">True</property>
+                                        <property name="can-focus">False</property>
+                                        <property name="orientation">vertical</property>
+                                        <property name="spacing">6</property>
+                                        <child>
+                                          <object class="GtkBox" id="boxSCALEALL">
+                                            <property name="visible">True</property>
+                                            <property name="can-focus">False</property>
+                                            <property name="spacing">12</property>
+                                            <child>
+                                              <object class="GtkLabel" id="labelSF">
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">False</property>
+                                                <property name="label" translatable="yes" context="printdialog|labelSF">_Scaling factor:</property>
+                                                <property name="use-underline">True</property>
+                                                <property name="mnemonic-widget">spinED_SCALEALL</property>
+                                                <property name="xalign">0</property>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkSpinButton" id="spinED_SCALEALL">
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">True</property>
+                                                <property name="activates-default">True</property>
+                                                <property name="truncate-multiline">True</property>
+                                                <property name="adjustment">adjustmentScalingFactor</property>
+                                                <child internal-child="accessible">
+                                                  <object class="AtkObject" id="spinED_SCALEALL-atkobject">
+                                                    <property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|spinED_SCALEALL">Enter a scaling factor. Factors less than 100 reduce the pages, higher factors enlarge the pages.</property>
+                                                  </object>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <!-- n-columns=2 n-rows=2 -->
+                                          <object class="GtkGrid" id="gridWH">
+                                            <property name="visible">True</property>
+                                            <property name="can-focus">False</property>
+                                            <property name="row-spacing">6</property>
+                                            <property name="column-spacing">12</property>
+                                            <property name="row-homogeneous">True</property>
+                                            <child>
+                                              <object class="GtkCheckButton" id="labelWP">
+                                                <property name="label" translatable="yes" context="printdialog|labelWP">_Width in pages:</property>
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">True</property>
+                                                <property name="receives-default">False</property>
+                                                <property name="use-underline">True</property>
+                                                <property name="draw-indicator">True</property>
+                                                <accessibility>
+                                                  <relation type="label-for" target="spinED_SCALEPAGEWIDTH"/>
+                                                </accessibility>
+                                              </object>
+                                              <packing>
+                                                <property name="left-attach">0</property>
+                                                <property name="top-attach">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkCheckButton" id="labelHP">
+                                                <property name="label" translatable="yes" context="printdialog|labelHP">_Height in pages:</property>
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">True</property>
+                                                <property name="receives-default">False</property>
+                                                <property name="use-underline">True</property>
+                                                <property name="draw-indicator">True</property>
+                                                <accessibility>
+                                                  <relation type="label-for" target="spinED_SCALEPAGEHEIGHT"/>
+                                                </accessibility>
+                                              </object>
+                                              <packing>
+                                                <property name="left-attach">0</property>
+                                                <property name="top-attach">1</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkSpinButton" id="spinED_SCALEPAGEWIDTH">
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">True</property>
+                                                <property name="activates-default">True</property>
+                                                <property name="truncate-multiline">True</property>
+                                                <property name="adjustment">adjustmentPage</property>
+                                                <accessibility>
+                                                  <relation type="labelled-by" target="labelWP"/>
+                                                </accessibility>
+                                                <child internal-child="accessible">
+                                                  <object class="AtkObject" id="spinED_SCALEPAGEWIDTH-atkobject">
+                                                    <property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|spinED_SCALEPAGEWIDTH">Enter the maximum number of pages to be printed horizontally across.</property>
+                                                  </object>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property name="left-attach">1</property>
+                                                <property name="top-attach">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkSpinButton" id="spinED_SCALEPAGEHEIGHT">
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">True</property>
+                                                <property name="activates-default">True</property>
+                                                <property name="truncate-multiline">True</property>
+                                                <property name="adjustment">adjustmentPage1</property>
+                                                <accessibility>
+                                                  <relation type="labelled-by" target="labelHP"/>
+                                                </accessibility>
+                                                <child internal-child="accessible">
+                                                  <object class="AtkObject" id="spinED_SCALEPAGEHEIGHT-atkobject">
+                                                    <property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|spinED_SCALEPAGEHEIGHT">Enter the maximum number of pages to be printed vertically stacked.</property>
+                                                  </object>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property name="left-attach">1</property>
+                                                <property name="top-attach">1</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkBox" id="boxNP">
+                                            <property name="visible">True</property>
+                                            <property name="can-focus">False</property>
+                                            <property name="spacing">12</property>
+                                            <child>
+                                              <object class="GtkLabel" id="labelNP">
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">False</property>
+                                                <property name="label" translatable="yes" context="printdialog|labelNP">N_umber of pages:</property>
+                                                <property name="use-underline">True</property>
+                                                <property name="mnemonic-widget">spinED_SCALEPAGENUM</property>
+                                                <property name="xalign">0</property>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkSpinButton" id="spinED_SCALEPAGENUM">
+                                                <property name="visible">True</property>
+                                                <property name="can-focus">True</property>
+                                                <property name="activates-default">True</property>
+                                                <property name="truncate-multiline">True</property>
+                                                <property name="adjustment">adjustmentPage2</property>
+                                                <child internal-child="accessible">
+                                                  <object class="AtkObject" id="spinED_SCALEPAGENUM-atkobject">
+                                                    <property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|spinED_SCALEPAGENUM">Enter the maximum number of pages to be printed.</property>
+                                                  </object>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">2</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="left-attach">1</property>
+                                        <property name="top-attach">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBoxText" id="comboLB_SCALEMODE">
+                                        <property name="visible">True</property>
+                                        <property name="can-focus">False</property>
+                                        <items>
+                                          <item translatable="yes" context="printdialog|comboLB_SCALEMODE">Reduce/enlarge printout</item>
+                                          <item translatable="yes" context="printdialog|comboLB_SCALEMODE">Shrink print range(s) to width/height</item>
+                                          <item translatable="yes" context="printdialog|comboLB_SCALEMODE">Shrink print range(s) on number of pages</item>
+                                        </items>
+                                        <child internal-child="accessible">
+                                          <object class="AtkObject" id="comboLB_SCALEMODE-atkobject">
+                                            <property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|comboLB_SCALEMODE">Select a scaling mode from the list box. Appropriate controls will be shown below the list box.</property>
+                                          </object>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="left-attach">1</property>
+                                        <property name="top-attach">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                  </object>
+                                </child>
+                                <child type="label">
+                                  <object class="GtkLabel" id="label3d">
+                                    <property name="visible">True</property>
+                                    <property name="can-focus">False</property>
+                                    <property name="label" translatable="yes" context="printdialog|label3d">Scale</property>
+                                    <attributes>
+                                      <attribute name="weight" value="bold"/>
+                                    </attributes>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">3</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>
diff --git a/vcl/unx/generic/print/genprnpsp.cxx b/vcl/unx/generic/print/genprnpsp.cxx
index 30c4f884a041..d6f6b5754a70 100644
--- a/vcl/unx/generic/print/genprnpsp.cxx
+++ b/vcl/unx/generic/print/genprnpsp.cxx
@@ -469,6 +469,7 @@ void PspSalInfoPrinter::InitPaperFormats( const ImplJobSetup* )
             m_aJobData.m_pParser->getPaperDimension( pValue->m_aOption, nWidth, nHeight );
             PaperInfo aInfo(PtTo10Mu( nWidth ), PtTo10Mu( nHeight ));
             m_aPaperFormats.push_back( aInfo );
+            //
         }
     }
 }
-- 
2.40.1

